package com.eos.control.action.emp;

import java.util.ArrayList;
import java.util.List;

import com.eos.common.tool.DataCacheUtil;
import com.eos.common.tool.PageModelUtil;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.SysRole;
import com.hf.utils.StringUtil;

public class RoleListAction extends AbstractBaseAction {
	private static final long serialVersionUID = -8863739787711482286L;
	private String roleName;
	private String roleStatus;
	private Integer pageNum;
	private Integer numPerPage;
	private List<SysRole> roleList;
	private Integer totalCount;
	
	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getRoleStatus() {
		return roleStatus;
	}

	public void setRoleStatus(String roleStatus) {
		this.roleStatus = roleStatus;
	}

	public Integer getPageNum() {
		return pageNum;
	}

	public void setPageNum(Integer pageNum) {
		this.pageNum = pageNum;
	}

	public Integer getNumPerPage() {
		return numPerPage;
	}

	public void setNumPerPage(Integer numPerPage) {
		this.numPerPage = numPerPage;
	}

	public List<SysRole> getRoleList() {
		return roleList;
	}

	public Integer getTotalCount() {
		return totalCount;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String execute() {
		try {
			if (StringUtil.isEmpty(roleStatus)) {
				roleStatus = "2";
			}
			if(null == pageNum || pageNum ==0) pageNum = 1;
			if(null == numPerPage || numPerPage ==0) numPerPage = PAGE_SIZE;
			List<SysRole> rlist = DataCacheUtil.getAllSysRole();
			if(!"2".equals(roleStatus.trim())){
				if(null != rlist && rlist.size()>0){
					List<SysRole> list = new ArrayList<SysRole>();
					for(SysRole role : rlist){
						if(roleStatus.equals(role.getStatus())){
							list.add(role);
						}
					}
					PageModelUtil pdm = new PageModelUtil(list, PAGE_SIZE);
					roleList = (List<SysRole>) pdm.getCurrentPage(pageNum);
					totalCount= null != list ? rlist.size() : 0;
				}
			}else{
				PageModelUtil pdm = new PageModelUtil(rlist, PAGE_SIZE);
				roleList = (List<SysRole>) pdm.getCurrentPage(pageNum);
				totalCount= null != rlist ? rlist.size() : 0;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return SUCCESS;
	}
}
